#pragma once
#include <iostream>
#include <string>

std::string opers = "+-*/%";

enum // 规定错误码
{
    DivZero = 1, // 当 除数为0时
    ModZero,     // 当 %的时候 ，xx % 0时
    Unknown      // 出现错误的符号时
};

class Task
{
private:
    int data1_; //
    int data2_;
    char oper_;

    int exitcode_; // 错误码，判断结果是否合理，默认为0
    int result_;   // 结果

public:
    Task(int x, int y, char op) : data1_(x), data2_(y), oper_(op), result_(0), exitcode_(0)
    {
    }

    ~Task()
    {
    }

    void run()
    {
        switch (oper_)
        {
        case '+':
            result_ = data1_ + data2_;
            break;
        case '-':
            result_ = data1_ - data2_;
            break;
        case '*':
            result_ = data1_ * data2_;
            break;
        case '/':
        {
            if (data2_ == 0)
                exitcode_ = DivZero;
            else
                result_ = data1_ / data2_;
        }
        break;
        case '%':
        {
            if (data2_ == 0)
                exitcode_ = ModZero;
            else
                result_ = data1_ % data2_;
        }
        break;
        default:
            exitcode_ = Unknown;
            break;
        }
    }

    //两数运算 所指向的任务
    std::string GetTask()
    {
        std::string r = std::to_string(data1_);
        r += oper_;
        r += std::to_string(data2_);
        r += "= ";
        return r;
    }

    //两数运算的结果
    std::string GetResult()
    {
        std::string r = std::to_string(result_);
        r += "[code: ";
        r += std::to_string(exitcode_);
        r += "]";

        return r;
    }

};